<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>透明的单例模式</title>
</head>
<body>
<script>
    var CreateDiv = (function () {
        var instance;
        var CreateDiv = function (html) {
            if(instance) return instance;
            this.html = html;
            this.init();
            return instance = this;
        };

        CreateDiv.prototype.init = function () {
            var div = document.createElement('div');
            div.innerHTML = this.html;
            document.body.appendChild(div);
        };

        return CreateDiv;
    })();

    var a = new CreateDiv('sven1');
    var b = new CreateDiv('sven2');
    console.log(a);
    console.log(b);
    console.log(a === b);
</script>
</body>
</html>